﻿using ProduceBasicData.Domain.Entities;
using ProduceBasicData.Domain.FactoryModeling;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProduceBasicData.Domain.Material
{
    /// <summary>
    /// BOM
    /// </summary>
    public class BOMInfoModel : BaseModel
    {
        /// <summary>
        /// 系统编码
        /// </summary>
        public string? BOMCode { get; set; }
        /// <summary>
        /// BOM名称
        /// </summary>
        public string BOMName { get; set; }
        /// <summary>
        /// BOM版本
        /// </summary>
        public string BomVersion { get; set; }
        /// <summary>
        /// BOM类型
        /// </summary>
        public string BomType { get; set; }
        /// <summary>
        /// BOM阶别
        /// </summary>
        public string BOMSteps { get; set; }
        /// <summary>
        /// BOM层级编码
        /// </summary>
        public int BOMLevel { get; set; }
        
        /// <summary>
        /// 群组物料ID
        /// </summary>
        public int? MaterialGroupId { get; set; }
        
        /// <summary>
        /// 产品物料ID
        /// </summary>
        public int? ProductMaterialId { get; set; }
        
        /// <summary>
        /// 工序ID
        /// </summary>
        public int ProcessId { get; set; }
        
        /// <summary>
        /// 父级BOM ID（用于添加下级）
        /// </summary>
        public int? ParentBOMId { get; set; }
        
        /// <summary>
        /// 工序导航属性
        /// </summary>
        [ForeignKey("ProcessId")]
        public virtual ProcessModel Process { get; set; }
        
        /// <summary>
        /// 父级BOM导航属性
        /// </summary>
        [ForeignKey("ParentBOMId")]
        public virtual BOMInfoModel ParentBOM { get; set; }
        
        /// <summary>
        /// 子级BOM集合
        /// </summary>
        public virtual ICollection<BOMInfoModel> ChildBOMs { get; set; } = new List<BOMInfoModel>();
        
        /// <summary>
        /// 工序编码（动态获取）
        /// </summary>
        [NotMapped]
        public string ProcessCode => Process?.Processcode ?? string.Empty;
        
        /// <summary>
        /// 工序名称（动态获取）
        /// </summary>
        [NotMapped]
        public string ProcessName => Process?.Processname ?? string.Empty;
        
        /// <summary>
        /// BOM用量
        /// </summary>
        public int? BOMDosage { get; set; }
        
        /// <summary>
        /// BOM描述
        /// </summary>
        public string BOMDesc { get; set; }
        
        /// <summary>
        /// 备注
        /// </summary>
        public string Remarks { get; set; }

    }
}
